package com.zhuoyue.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletRequest;

import com.zhuoyue.common.annotation.Log;
import com.zhuoyue.common.core.controller.BaseController;
import com.zhuoyue.common.core.domain.AjaxResult;
import com.zhuoyue.common.core.page.TableDataInfo;
import com.zhuoyue.common.enums.BusinessType;
import com.zhuoyue.common.utils.poi.ExcelUtil;

import com.zhuoyue.system.domain.dto.AutoMatePoReqDTO;
import com.zhuoyue.system.domain.po.TblAutoMatePo;
import com.zhuoyue.system.domain.vo.AutomationVo;
import com.zhuoyue.system.mapper.SysDeptMapper;
import com.zhuoyue.web.utils.OrgCodeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zhuoyue.system.service.ITblAutomateService;


/**
 * 自动化(联动)Controller
 *
 * @author hewenze
 * @date 2020-08-10
 */
@RestController
@RequestMapping("/system/automate")
@Api(value = "自动化接口", tags = "自动化接口")
public class TblAutomateController extends BaseController {
    @Autowired
    private ITblAutomateService tblAutomateService;

    @Autowired
    private OrgCodeUtils orgCodeUtils;
    @Autowired
    private SysDeptMapper sysDeptMapper;

    /**
     * 查询自动化(联动)列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询自动化(联动)列表", notes = "查询自动化(联动)列表")
    public TableDataInfo list(AutoMatePoReqDTO autoMatePoReq) {

        TblAutoMatePo tblAutoMatePo = new TblAutoMatePo().doToDto(autoMatePoReq);
        startPage();
        List<AutomationVo> list = tblAutomateService.selectTblAutomateList(tblAutoMatePo);
        return getDataTable(list);
    }

    /**
     * 查询本地场景列表
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "查询场景信息", notes = "查询场景信息")
    public AjaxResult list(@PathVariable("id") String id) {
        AutomationVo automationVo = tblAutomateService.selectById(id);
        return AjaxResult.success(automationVo);
    }

    /**
     * 导出自动化(联动)列表
     */
    @Log(title = "自动化(联动)", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation(value = "导出自动化(联动)列表", notes = "导出自动化(联动)列表")
    public AjaxResult export(TblAutoMatePo tblAutoMatePo, HttpServletRequest request) {
        tblAutoMatePo.setOrganizationCode(orgCodeUtils.getOrgCode(request));
        tblAutoMatePo.setPageNum(null);
        tblAutoMatePo.setPageSize(null);
        List<AutomationVo> list = tblAutomateService.selectTblAutomateList(tblAutoMatePo);
        ExcelUtil<AutomationVo> util = new ExcelUtil<AutomationVo>(AutomationVo.class);
        return util.exportExcel(list, "自动化");
    }
}
